package com.zjw.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zjw.domain.entity.Notice;
import com.zjw.domain.vo.NoticeVo;
import com.zjw.domain.vo.ResponseResult;
import com.zjw.mapper.NoticeMapper;
import com.zjw.service.NoticeService;
import com.zjw.service.UserService;
import com.zjw.utils.BeanCopyUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 系统公告表(Notice)表服务实现类
 *
 * @author lkzy
 * @since 2024-01-02 15:36:28
 */
@Service("noticeService")
public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice> implements NoticeService {


    @Autowired
    private UserService userService;

    @Override
    public ResponseResult getNoticeList() {
        LambdaQueryWrapper<Notice> wrapper = new LambdaQueryWrapper<>();

//        按时间降序
        wrapper.orderByDesc(Notice::getCreateTime);

        List<Notice> list = list(wrapper);
        List<NoticeVo> res = BeanCopyUtil.copyList(list, NoticeVo.class);

        res.stream().forEach(i->{
//            更具创建者id获取创建者用户名
            i.setCreateByName(userService.getUserNameById(i.getCreateBy()));
        });

        return ResponseResult.ok(res);
    }
}
